home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / OWLINC.PAK / UPDOWN.H < prev    next >
C/C++ Source or Header  |  1997-05-06  |  9KB  |  285 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows
  3. // Copyright (c) 1995, 1997 by Borland International, All Rights Reserved
  4. //
  5. //$Revision:   10.7  $
  6. //
  7. // Definition of class TUpDown.
  8. //----------------------------------------------------------------------------
  9. #if !defined(OWL_UPDOWN_H)
  10. #define OWL_UPDOWN_H
  11.  
  12. #if !defined(OWL_CONTROL_H)
  13. # include <owl/control.h>
  14. #endif
  15. #if !defined(OWL_COMMCTRL_H)
  16. # include <owl/commctrl.h>
  17. #endif
  18. #if !defined(OWL_BITSET_H)
  19. # include <owl/bitset.h>
  20. #endif
  21.  
  22. #if defined(BI_NAMESPACE)
  23. namespace OWL {
  24. #endif
  25.  
  26. // Generic definitions/compiler options (eg. alignment) preceeding the 
  27. // definition of classes
  28. #include <services/preclass.h>
  29.  
  30. //
  31. // class TUDAccel
  32. // ~~~~~ ~~~~~~~~
  33. //  Thin (real thin) wrapper for the UDACCEL structure which contains
  34. //  information about updown accelarators. The main purpose of this
  35. //  class is to have a place-holder for future abstraction/encapsulation.
  36. //
  37. class TUDAccel : public UDACCEL {
  38. };
  39.  
  40. //
  41. // class TUpDown
  42. // ~~~~~ ~~~~~~~
  43. // TUpDown encapsulates an up-down control, a window with a pair of arrow
  44. // buttons that the user can click to increment or decrement a value.
  45. //
  46. class _OWLCLASS TUpDown : public TControl, public TBitFlags<uint> {
  47.   public:
  48.     TUpDown(TWindow* parent,
  49.             int      id,
  50.             int x, int y, int w, int h,
  51.             TWindow* buddy = 0,
  52.             TModule* module = 0);
  53.  
  54.     TUpDown(TWindow* parent, int resourceId, TWindow* buddy = 0, TModule* module = 0);
  55.  
  56.     int           GetAccel(int count, TUDAccel far* accels) const;
  57.     int           GetBase() const;
  58.     HWND          GetBuddy() const;
  59.     int32         GetPos() const;
  60.     uint32        GetRange() const;
  61.     void          GetRange(int& lower, int& upper) const;
  62.  
  63.     bool          SetAccel(int count, const TUDAccel far* accels);
  64.     int           SetBase(int base);
  65.     HWND          SetBuddy(HWND hBuddy);
  66.     int32         SetPos(int pos);
  67.     void          SetRange(int lower, int upper);
  68.  
  69.   protected:
  70.     // Override TWindow virtual member functions
  71.     //
  72.     char far*     GetClassName();
  73.     void          PerformCreate(int);
  74.     void          EvVScroll(uint, uint, HWND);
  75.     void          EvHScroll(uint, uint, HWND);
  76.  
  77. #if !defined(OWL_NATIVECTRL_ALWAYS)
  78.  
  79.     // Helper routines/members used when ObjectWindows provides the
  80.     // underlying implementation of the UpDown control...
  81.  
  82.     // Overriden virtual(s) from TWindow
  83.     //
  84.     void          Paint(TDC& dc, bool erase, TRect& rect);
  85.     void          SetupWindow();
  86.  
  87.     // Message Handlers
  88.     //
  89.     void          EvEnable(bool enabled);
  90.     void          EvShowWindow(bool show, uint status);
  91.     void          EvCancelMode();
  92.     void          EvTimer(uint timerId);
  93.     void          EvLButtonDown(uint modKeys, TPoint& point);
  94.     void          EvLButtonDblClk(uint modKeys, TPoint& point);
  95.     void          EvLButtonUp(uint modKeys, TPoint& point);
  96.     void          EvMouseMove(uint modKeys, TPoint& point);
  97.  
  98. /*  
  99.     // Maintains internal state of the control
  100.     //
  101.     uint          CtlState;
  102.  
  103.     void          Set(uint flg);
  104.     void          Clear(uint flg);
  105.     bool          IsSet(uint flg);
  106. */
  107.  
  108.     // Enumeration describing the state and attributes of the updown control
  109.     //
  110.     enum TCtlState {
  111.       csGrayed    = 0x0001,         // Control is grayed
  112.       csHidden    = 0x0002,         // Control is hidden
  113.       csMouseOut  = 0x0004,         // Mouse is outside client are
  114.       csIncrement = 0x0008,         // Control's currently incrementing
  115.       csDecrement = 0x0010,         // Control's currently decrementing
  116.       csTimer1On  = 0x0020,         // Initial/delayed timer is enabled
  117.       csTimer2On  = 0x0040          // Repeat/hold timer is enabled
  118.     };
  119.  
  120.     // Helper routines used by ObjectWindows' implementation
  121.     //
  122.     void          Action();
  123.     void          GetSpinRect(TRect& rect, bool incRect);
  124.     void          GetSpinRectFromState(TRect& rect);
  125.     uint          GetSpinRectFromPoint(TRect& rect, const TPoint& pt);
  126.     void          SetBuddyInt() const;
  127.     void          GetBuddyInt();
  128.  
  129.   private:
  130.     // Variables used by ObjectWindows' implementaion
  131.     //
  132.     HWND          BuddyHandle;
  133.     int           Base;
  134.  
  135. #endif  // !OWL_NATIVECTRL_ALWAYS
  136.  
  137.   private:
  138.     // Hidden to prevent accidental copying or assignment
  139.     //
  140.     TUpDown(const TUpDown&);
  141.     TUpDown& operator =(const TUpDown&);
  142.  
  143.     // Data members used to hold creation attributes of control
  144.     // NOTE: These variables are not kept in sync with the actual
  145.     //       state of the control when the class makes use of the
  146.     //       CommonControl implementation of 'UPDOWN'
  147.     //
  148.     TWindow*      Buddy;                    // Pointer to buddy window
  149.     int           Lower;                    // Low end of range
  150.     int           Upper;                    // High end of range
  151.     int           Pos;                      // Current/Staring posotion
  152.  
  153.   DECLARE_RESPONSE_TABLE(TUpDown);
  154. };
  155.  
  156. // Generic definitions/compiler options (eg. alignment) following the 
  157. // definition of classes
  158. #include <services/posclass.h>
  159.  
  160. #if defined(BI_NAMESPACE)
  161. } // namespace OWL
  162. #endif
  163.  
  164. //----------------------------------------------------------------------------
  165. // Inlines
  166. //
  167.  
  168. #if defined(OWL_NATIVECTRL_ALWAYS)
  169.  
  170. // When building OWL to always use the system's implementation of 
  171. // CommonControls, the following methods are mere wrappers around
  172. // the predefined UpDown messages (i.e. UDM_xxxx)
  173. //
  174.  
  175. // Retrieves acceleration information for the underlying up-down control
  176. //
  177. inline int TUpDown::GetAccel(int count, TUDAccel far* accels) const {
  178.   return (int)CONST_CAST(TUpDown*,this)->SendMessage(UDM_GETACCEL, count, TParam2(accels));
  179. }
  180.  
  181. // Retrieves the current radix base of the underlying up-down control.
  182. // Return value is either 10 or 16.
  183. //
  184. inline int TUpDown::GetBase() const {
  185.   return (int)CONST_CAST(TUpDown*,this)->SendMessage(UDM_GETBASE);
  186. }
  187.  
  188. // Retrieves handle if buddy window of underlying up-down control
  189. //
  190. inline HWND TUpDown::GetBuddy() const {
  191.   return (HWND)CONST_CAST(TUpDown*,this)->SendMessage(UDM_GETBUDDY);
  192. }
  193.  
  194. // Returns current position of underlying up-down control. The high-order
  195. // word in non-zero in case of an error. The current position is in the
  196. // low-order word.
  197. //
  198. inline int32 TUpDown::GetPos() const {
  199.   return (int32)LoUint16(CONST_CAST(TUpDown*,this)->SendMessage(UDM_GETPOS));
  200. }
  201.  
  202. // Retrieves the minimum and maximum range of the underlying up-down control.
  203. // The low-order word contains the maximum position while the high-order
  204. // word contains the minimum position.
  205. //
  206. inline uint32 TUpDown::GetRange() const {
  207.   return (uint32)CONST_CAST(TUpDown*,this)->SendMessage(UDM_GETRANGE);
  208. }
  209.  
  210. // Retrieves the minimum and maximum range of the underlying up-down control
  211. // into the specified 'lower' and 'upper' variables respectively.
  212. //
  213. inline void TUpDown::GetRange(int& lower, int& upper) const {
  214.   uint32 ret = CONST_CAST(TUpDown*,this)->SendMessage(UDM_GETRANGE);
  215.   lower = HiUint16(ret);
  216.   upper = LoUint16(ret);
  217. }
  218.  
  219. // Set the acceleration of the underlying up-down control. 'count' 
  220. // specifies the number of structures specified in 'accels' while the
  221. // latter is the address of an array of TUDAccel structures.
  222. //
  223. inline bool TUpDown::SetAccel(int count, const TUDAccel far* accels) {
  224.   return ToBool(SendMessage(UDM_SETACCEL, count, TParam2(accels)));
  225. }
  226.  
  227. // Sets the radix of the underlying up-down control. The 'base' parameter
  228. // should be either '10' or '16' for decimal and hexadecimal respectively.
  229. //
  230. inline int TUpDown::SetBase(int base) {
  231.   return int(SendMessage(UDM_SETBASE, base));
  232. }
  233.  
  234. // Sets the buddy window of the underlying up-down control.
  235. //
  236. inline TWindow::THandle TUpDown::SetBuddy(HWND hBuddy) {
  237.   return TWindow::THandle(SendMessage(UDM_SETBUDDY, TParam1(hBuddy)));
  238. }
  239.  
  240. // Sets the current position of the underlying up-down control. The
  241. // return value is the previous position.
  242. //
  243. inline int32 TUpDown::SetPos(int pos) {
  244.   return SendMessage(UDM_SETPOS, 0, MkParam2(pos, 0));
  245. }
  246.  
  247. // Sets the minimum and maximum positions of the up-down control. 
  248. // NOTE: Neither 'lower' nor 'upper' can be greater than UD_MAXVAL or
  249. // less than UD_MINVAL. Futhermore, the difference between the two
  250. // positions must not exceed UD_MAXVAL;
  251. //
  252. inline void TUpDown::SetRange(int lower, int upper) {
  253.   PRECONDITION(lower >= UD_MINVAL);
  254.   PRECONDITION(lower <= UD_MAXVAL);
  255.   PRECONDITION(upper >= UD_MINVAL);
  256.   PRECONDITION(upper <= UD_MAXVAL);
  257.   PRECONDITION(abs(upper-lower) <= UD_MAXVAL);
  258.   SendMessage(UDM_SETRANGE, 0, MkParam2(upper, lower));
  259. }
  260.  
  261. #endif  // OWL_NATIVECTRL_ALWAYS
  262.  
  263. /* 
  264. #if !defined(OWL_NATIVECTRL_ALWAYS)
  265. //
  266. inline void TUpDown::Set(uint flg) {
  267.   CtlState |= flg;
  268. }
  269.  
  270. //
  271. inline void TUpDown::Clear(uint flg) {
  272.   CtlState &= ~flg;
  273. }
  274.  
  275. //
  276. inline bool TUpDown::IsSet(uint flg) {
  277.   return (CtlState & flg) != 0;
  278. }
  279.  
  280. #endif  // !OWL_NATIVECTRL_ALWAYS
  281. */
  282.  
  283.  
  284. #endif  // OWL_UPDOWN_H
  285.